/**
 *  Copyright 2009-2010 Steven Ottenhoff (Dual-IT)
 * 
 *  This file is part of Clazzified.
 *
 *  Clazzified is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Clazzified is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Clazzified.  If not, see http://www.gnu.org/licenses/gpl.
 * 
 */

package nl.dualit.clazzified.core.model.attribute.constraint;

import java.util.HashMap;
import java.util.Map;

import nl.dualit.clazzified.core.model.attribute.IAttribute;
import nl.dualit.clazzified.core.model.object.IObjektAttribute;
import nl.dualit.clazzified.store.clazz.ConstraintFields;

abstract class AbstractConstraint implements IConstraint {
	private IAttribute attribute;
	private Long id;
	String name;
	String description;
	ConstraintTypes type;
	String value;
	
	private AbstractConstraint(){
		throw new IllegalArgumentException("Empty onstructor not allowed");
	}
	
	AbstractConstraint( IAttribute attribute ){
		
		this.attribute = attribute;	
	
	}

	public IAttribute getAttribute() {
		
		return attribute;
	}

	@Override
	public String getName() {
		return name;
	}
	
	@Override
	public void setName( String name ) {
		this.name = name;
	}
	
		
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public ConstraintTypes getType() {
		return type;
	}

	public void setType(ConstraintTypes type) {
		this.type = type;
	}

	public void setAttribute(IAttribute attribute) {
		this.attribute = attribute;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public Map<ConstraintFields,String> getDataMap(){
		
		Map<ConstraintFields, String> map = new HashMap<ConstraintFields,String>();
		map.put( ConstraintFields.CONSTRAINT_ID, id.toString() );
		map.put( ConstraintFields.CONSTRAINT_NAME, name );
		map.put( ConstraintFields.CONSTRAINT_DESCRIPTION, description );
		map.put( ConstraintFields.ATTRIBUTE_ID, attribute.getId().toString() );
		map.put( ConstraintFields.TYPE_NAME, getType().typeName() );
		map.put( ConstraintFields.CONSTRAINT_VALUE, getValue().toString() );
		
		return map;
	
	}
}
